package com.psp.park.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.psp.park.controller.res.*;
import com.psp.park.controller.res.bean.*;
import com.psp.park.controller.springmvc.req.*;

/**
 * 地址-相关接口
 **/
@Controller
@RequestMapping(value = "/park/address", produces = "application/json")
public class SAddressController {
	@Autowired
	com.psp.park.controller.AddressController addressController;

	/**
	 * 地址详情
	 **/
	@RequestMapping("/v1/getDetail")
	@ResponseBody
	public ObjectResult<RAddressDetailBean> getDetail(@Validated GetAddressDetailParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RAddressDetailBean> res = new ObjectResult<RAddressDetailBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return addressController.getDetail(param, request, response);
	}

	/**
	 * 地址列表
	 **/
	@RequestMapping("/v1/list")
	@ResponseBody
	public ListResult<RAddressListBean> list(@Validated GetAddressListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RAddressListBean> res = new ListResult<RAddressListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return addressController.list(param, request, response);
	}

	/**
	 * 地址保存
	 **/
	@RequestMapping("/v1/save")
	@ResponseBody
	public BaseResult save(@Validated GetAddressSaveParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return addressController.save(param, request, response);
	}

	/**
	 * 地址删除
	 **/
	@RequestMapping("/v1/delete")
	@ResponseBody
	public BaseResult delete(@Validated GetAddressDeleteParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return addressController.delete(param, request, response);
	}
}
